from lib.webui import *
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from hyrobot.common import CHECK_POINT, STEP


class c73309:
    name = '验证导航栏缩放功能-c73309'  # 测试用例名字

    # 初始化方法
    def setup(self):
        STEP(1, '登陆网站')
        driver = open_browser()
        mgr_login(driver)

    # 清除方法
    def teardown(self):
        driver = get_global_webdriver()
        driver.quit()

    # 测试用例步骤
    def teststeps(self):
        # 获取webdriver对象 对应 已经登录好的浏览器
        driver = get_global_webdriver()
        # driver = webdriver.Firefox()

        STEP(2,"点击导航栏申请记录")
        extending_button = driver.find_element_by_id("hamburger-container")
        try:
            driver.find_element(By.CLASS_NAME,"el-tooltip")
            extending_button.click()
        except:
            print("左侧栏没有隐藏")
        left_button = driver.find_elements(By.CLASS_NAME,"el-menu-item")
        left_button[1].click()
        expected_title = "申请记录"
        got_title = driver.find_element(By.CLASS_NAME,"no-redirect").text
        CHECK_POINT("提示信息是否一致", expected_title == got_title)

        STEP(3, "点击最上处首页")
        time.sleep(1)
        top_button = driver.find_elements(By.CLASS_NAME,"el-breadcrumb__inner")
        top_button[0].click()
        time.sleep(1)
        expected_title1 = "产品列表"
        got_title1 = driver.find_element(By.CLASS_NAME, "no-redirect").text
        CHECK_POINT("提示信息是否一致", expected_title1 == got_title1)

        STEP(4, "点击导航栏缩放按钮")
        # 收回
        extending_button.click()
        # 展开
        extending_button.click()
        expected_words = ["产品列表","申请记录"]
        # xpath两浏览器是一样的
        got_left_word0 = driver.find_element(By.XPATH,
        "//*/div/div[1]/ul/div[1]/a/li/span"
                                            ).text
        got_left_word1 = driver.find_element(By.XPATH,
        "/html/body/div/div/div[1]/ul/div[2]/a/li/span"
                                             ).text
        CHECK_POINT("提示信息是否一致", expected_words[0] == got_left_word0
                    and expected_words[1] == got_left_word1)




